<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/style.css"/>
    <link href="assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/ace.min.css" />
    <link rel="stylesheet" href="font/css/font-awesome.min.css" />
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="assets/layer/layer.js" type="text/javascript" ></script>
    <script src="assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/typeahead-bs2.min.js"></script>
    <script src="assets/js/jquery.dataTables.min.js"></script>
    <script src="assets/js/jquery.dataTables.bootstrap.js"></script>

    <title>个人信息管理</title>
    <style type="text/css">
        .businessLicense label{
            margin: 30px;
        }
        .businessLicense img{
            width: 100px;
            height: 80px;
        }
    </style>
</head>

<body>
<div class="clearfix">
    <div class="admin_info_style">
        <div class="admin_modify_style" id="Personal">
            <div class="type_title">老板信息 </div>
            <div class="xinxi">
<!--                <div class="form-group">-->
<!--                    <label class="" for="upload0" >-->
<!--                        <img src="images/文件上传.png" alt=""  id="img0" style="width: 120px;height: 100px;margin-left: 25px"/>-->
<!--                    </label>-->
<!--                    <input type="file" id="upload0"  style="position:absolute;clip:rect(0 0 0 0);"  accept="image/gif,image/jpeg,image/jpg,image/png" disabled="disabled" value="img0">-->
<!--                </div>-->
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >用户名： </label>
                    <div class="col-sm-9"><input type="text" name="用户名" id="username" value="张小泉" class="col-xs-7 text_info" disabled="disabled">
                        &nbsp;&nbsp;&nbsp;<a href="javascript:ovid()" onclick="change_Password()" class="btn btn-warning btn-xs">修改密码</a></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >ID: </label>
                    <div class="col-sm-9" > <span id="bossId">124435</span></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >移动电话： </label>
                    <div class="col-sm-9"><input type="text" name="移动电话" id="iphone" value="13567878908" class="col-xs-7 text_info" disabled="disabled"></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >身份号码： </label>
                    <div class="col-sm-9"><input type="text" name="身份证号码" id="idCard" value="430426199907048852" class="col-xs-7 text_info" disabled="disabled"></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >电子邮箱： </label>
                    <div class="col-sm-9"><input type="text" name="电子邮箱" id="email" value="567890@qq.com" class="col-xs-7 text_info" disabled="disabled"></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >权限： </label>
                    <div class="col-sm-9" > <span>老板</span></div>
                </div>
                <div class="Button_operation clearfix">
                    <button onclick=modify("Personal"); class="btn btn-danger radius" type="submit">修改信息</button>
                    <button onclick="save_info();" class="btn btn-success radius" type="button">保存修改</button>
                </div>
            </div>
        </div>
        <div class="admin_modify_style" id="business">
            <div class="type_title">店铺信息</div>
            <div class="recording_list">
                <div>
                    <label class="" for="upload" style="margin-left: 30px">
                        <img src="images/默认店铺.png" alt="" style="width: 100px;height: 80px;" id="img"/>
                    </label>
                    <form enctype="multipart/form-data"><input type="file" id="upload" style="position:absolute;clip:rect(0 0 0 0);"  accept="image/gif,image/jpeg,image/jpg,image/png" disabled="disabled"></form>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >店铺名： </label>
                    <div class="col-sm-9"><input type="text" name="店铺名" id="businessName" value="妈了个鸡" class="col-xs-7 text_info" disabled="disabled"></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >粉丝数: </label>
                    <div class="col-sm-9" > <span id="businessFans">124435</span></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >星级: </label>
                    <div class="col-sm-9" > <span id="businessGrade">5</span></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >地址： </label>
                    <div class="col-sm-9"><input type="text" name="地址" id="businessAddress" value="湖南长沙" class="col-xs-7 text_info" disabled="disabled"></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >开店时间: </label>
                    <div class="col-sm-9" > <span id="businessTime">2018-01-10</span></div>
                </div>
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >简介： </label>
                    <div class="col-sm-9">
                        <textarea rows="5" cols="20" class="col-xs-7 text_info" style="height: 80px" disabled="disabled" id="synopsis"></textarea>
<!--                        <input type="text" name="简介" id="businessAbstract" value="567890@qq.com" class="col-xs-7 text_info" disabled="disabled">-->
                    </div>
                </div>
                <div class="Button_operation clearfix">
                    <button onclick=register(); class="btn btn-danger radius" type="submit">注册店铺</button>
                    <button onclick="saveInfoBusiness();" class="btn btn-success radius" type="button">提交</button>
                </div>
            </div>
        </div>
        <div class="admin_modify_style" id="">
            <div class="type_title">营业执照 </div>
            <div class="businessLicense">
                <label class="" for="upload1" >
                    <img src="images/文件上传.png" alt=""  id="img1"/>
                </label>
                    <input type="file" id="upload1" class="license" style="position:absolute;clip:rect(0 0 0 0);"  accept="image/gif,image/jpeg,image/jpg,image/png" disabled="disabled" value="img1">

                <label class="" for="upload2" >
                    <img src="images/文件上传.png"  alt=""  id="img2"/>
                </label>
                <input type="file" id="upload2" class="license" style="position:absolute;clip:rect(0 0 0 0);"  accept="image/gif,image/jpeg,image/jpg,image/png" disabled="disabled" value="img2">

                <label class="" for="upload3" >
                    <img src="images/文件上传.png" alt=""  id="img3"/>
                </label>
                <input type="file" id="upload3" class="license" style="position:absolute;clip:rect(0 0 0 0);"  accept="image/gif,image/jpeg,image/jpg,image/png" disabled="disabled" value="img3">

                <label class="" for="upload4" >
                    <img src="images/文件上传.png" alt=""  id="img4"/>
                </label>
                <input type="file" id="upload4" class="license" style="position:absolute;clip:rect(0 0 0 0);"  accept="image/gif,image/jpeg,image/jpg,image/png" disabled="disabled" value="img4">

                <label class="" for="upload5" >
                    <img src="images/文件上传.png" alt=""  id="img5"/>
                </label>
                <input type="file" id="upload5" class="license" style="position:absolute;clip:rect(0 0 0 0);"  accept="image/gif,image/jpeg,image/jpg,image/png" disabled="disabled" value="img5">
                <div class="Button_operation clearfix">
                    <button onclick="upBusinessLicense();" class="btn btn-danger radius" type="submit">添加</button>
                    <button onclick="saveInfoLicense();" class="btn btn-success radius" type="button">上传</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--修改密码样式-->
<div class="change_Pass_style" id="change_Pass">
    <ul class="xg_style">
        <li><label class="label_name">原&nbsp;&nbsp;密&nbsp;码</label><input name="原密码" type="password" class="" id="password"></li>
        <li><label class="label_name">新&nbsp;&nbsp;密&nbsp;码</label><input name="新密码" type="password" class="" id="Nes_pas"></li>
        <li><label class="label_name">确认密码</label><input name="再次确认密码" type="password" class="" id="c_mew_pas"></li>

    </ul>
    <!--       <div class="center"> <button class="btn btn-primary" type="button" id="submit">确认修改</button></div>-->
</div>
</body>
</html>
<script>
    //老板信息展示
    var bossId = $("#bossId");
    var username = $("input[name='用户名']");
    var iphone = $("input[name='移动电话']");
    var bossIdCard = $("input[name='身份证号码']")
    var email = $("input[name='电子邮箱']");
    var bossImg = $("#img0");       //老板头像
    $.ajax({
        url: "http://localhost:8080/SnacksShop/boss.do?type=bossInfo",
        type: "post",
        data:{

        },
        crossDomain: true,
        xhrFields: {
            withCredentials: true
        },
        type: "post",
        success:function (data){
            var obj = JSON.parse(data);
            // console.log(obj);
            if (obj.business.message == '200'){
                //老板信息
                var boss = obj.business.object.boss;
                bossId.text(boss.bossId);
                username.val(boss.bossName);
                bossIdCard.val(boss.bossIdCard);
                iphone.val(boss.bossPhone);
                email.val(boss.bosseMail);
                bossImg.attr("src",boss.bossImg);
                //店铺信息
                var business = obj.business.object;
                var img = business.businessImg
                $("#img").attr("src",img);
                $("#businessName").val(business.businessName);
                $("#businessFans").text(business.businessFans);
                $("#businessGrade").text(business.businessGrade);
                $("#businessAddress").val(business.businessAddress);
                $("#businessTime").text(new Date(business.businessTime.time).toLocaleDateString());
                $("#synopsis").val(business.businessAbstract);
                //营业执照信息
                // console.log(boss);
                $("#img1").attr("src",boss.bossPapers1);
                $("#img2").attr("src",boss.bossPapers2);
                $("#img3").attr("src",boss.bossPapers3);
                $("#img4").attr("src",boss.bossPapers4);
                $("#img5").attr("src",boss.bossPapers5);
            }
        },
        error:function (data){

        }
    });
    //文件上传
    function fileUp(formData,element) {
        $.ajax({
            type:"post",
            url:"http://47.110.246.191:8080/FileSys/file/load.do",
            data:formData,
            async:false,
            processData:false,
            contentType:false,
            success:function (data){
                layer.alert("上传成功！\r\n",{
                    title: '提示框',
                    icon:0,
                });
                var temp = data.substring(data.indexOf("http"));
                var imgUrl = temp.substring(0,temp.indexOf("\""));
                element.attr("type",imgUrl);
            },
            error:function (data){
                layer.alert("服务器错误！\r\n",{
                    title: '提示框',
                    icon:0,
                });
                alert("服务器错误");
            }
        });
    }
    //文件下载
    function fileDown() {

    }


    //按钮点击事件
    function modify(id){
        var parent = document.getElementById(id);       //板块id
        $("#upload0").attr("disabled", false);
        $(parent).find('.text_info').attr("disabled", false);
        $(parent).find('.text_info').addClass("add");
        $(parent).find('.xinxi').addClass("hover");
        $(parent).find('.btn-success').css({'display':'block'});
    };
    //店铺注册按钮
    function register() {
        var businessName = document.getElementById("businessName");  //某个文本id
        if ($(businessName).val() != ""){
            layer.alert("不可修改！\r\n",{
                title: '提示框',
                icon:0,
            });
            return false;
        }
        var parent = document.getElementById("business");       //板块id
        $("#upload").attr("disabled",false);
        $(parent).find('.text_info').attr("disabled", false);
        $(parent).find('.text_info').addClass("add");
        $(parent).find('.xinxi').addClass("hover");
        $(parent).find('.btn-success').css({'display':'block'});

    }
    //上传营业执照
    function upBusinessLicense() {
        var parent = document.getElementsByClassName("businessLicense");
        $(".license").attr("disabled", false);
        $(".license").each(function (){
            $(this).change(function (){
                var upload_input = $(this).val();
                if(upload_input == ""){
                    layer.alert("未选中文件！\r\n",{
                        title: '提示框',
                        icon:0,
                    });
                    return ;
                }
                var formData = new FormData();
                console.log($(this)[0].files.length)
                for (var i = 0; i < $(this)[0].files.length; i++) {
                    // console.log($("#upload")[0].files[i])
                    formData.append("file",$(this)[0].files[i]);
                }
                var img = document.getElementById($(this).attr("value"));
                var temp = "images/"+upload_input.substring(12);
                $(img).attr("src",temp);
                fileUp(formData,$(img));
                return false;
            });
        });
        $(parent).find('.btn-success').css({'display':'block'});
    }
    //老板信息保存
    function save_info(){
        var num=0;
        var str="";
        $(".xinxi input[type$='text']").each(function(n){
            if($(this).val()=="")
            {

                layer.alert(str+=""+$(this).attr("name")+"不能为空！\r\n",{
                    title: '提示框',
                    icon:0,
                });
                num++;
                return false;
            }
        });
        var usernameExist = $("#username").attr("value");
        var iphoneExist = $("#iphone").attr("value");
        var idCardExist = $("#idCard").attr("value");
        var emailExist = $("#email").attr("value");
        if (usernameExist == 'true'){
            layer.alert("用户名已存在 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
        if (iphoneExist == 'true'){
            layer.alert("手机号码已存在 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
        if (emailExist == 'true'){
            layer.alert("邮箱已存在 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
        if (idCardExist == 'true'){
            layer.alert("身份证号码已存在 \r\n",{
                title: '提示框',
                icon:0,
            });
        }

        if (usernameExist == 'true'|| iphoneExist == 'true' || emailExist == 'true' || idCardExist == 'true'){
            return false;
        }
        if(num>0){  return false;}
        else{
            var username = $("#username").val();
            var iphone = $("#iphone").val();
            var email = $("#email").val();
            var idCard = $("#idCard").val();
            var bossImg = $("#img0").attr("src");
            $.ajax({
                url: "http://localhost:8080/SnacksShop/boss.do?type=updateBoss",
                type: "post",
                data:{
                    username:username,
                    iphone:iphone,
                    email:email,
                    idCard:idCard,
                    bossImg:bossImg
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success:function (data){
                    var obj = JSON.parse(data);
                    // console.log(obj);
                    if (obj.status == '200'){
                        layer.alert('修改成功！',{
                            title: '提示框',
                            icon:1,
                        });
                    }else {
                        layer.alert('修改失败！',{
                            title: '提示框',
                            icon:0,
                        });
                    }
                },
                error:function (data){

                }
            });

            $('#Personal').find('.xinxi').removeClass("hover");
            $('#Personal').find('.text_info').removeClass("add").attr("disabled", true);
            $('#Personal').find('.btn-success').css({'display':'none'});
            // layer.close(index);

        }
    };
    //店铺信息保存
    function saveInfoBusiness() {
        var isExistBusinessName = $("#businessName").attr("value");
        var num = 0;
        var str = "";
        $(".recording_list input[type$='text']").each(function (n) {
            if ($(this).val() == "") {

                layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                    title: '提示框',
                    icon: 0,
                });
                num++;
                return false;
            }
        });
        if ($("#synopsis").val() == ""){
            layer.alert("简介不能为空 \r\n",{
                title: '提示框',
                icon:0,
            });
            num++;
            return false;
        }

        if (isExistBusinessName == 'true'){
            layer.alert("店铺名已存在 \r\n",{
                title: '提示框',
                icon:0,
            });
            return false;
        }
        if (num > 0) {
            return false;
        } else {
            var businessName = $("#businessName").val();
            var businessAddress = $("#businessAddress").val();
            var businessSynopsis = $("#synopsis").val();
            var businessImg = $("#img").attr("src");
            $.ajax({
                url: "http://localhost:8080/SnacksShop/boss.do?type=addBusiness",
                type: "post",
                data:{
                    businessImg:businessImg,
                    businessName:businessName,
                    businessAddress:businessAddress,
                    businessSynopsis:businessSynopsis
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success:function (data){
                    var obj = JSON.parse(data);
                    console.log(obj);
                    if (obj.status == '200'){
                        layer.alert('修改成功！',{
                            title: '提示框',
                            icon:1,
                        });
                    }else {
                        layer.alert('修改失败！',{
                            title: '提示框',
                            icon:0,
                        });
                    }
                },
                error:function (data){

                }
            });
            $('#business').find('.recording_list').removeClass("hover");
            $('#business').find('.text_info').removeClass("add").attr("disabled", true);
            $('#business').find('.btn-success').css({'display': 'none'});
        }
    }
    //营业执照保存
    function saveInfoLicense() {
        var img1 = $("#img1").attr("type");
        var img2 = $("#img2").attr("type");
        var img3 = $("#img3").attr("type");
        var img4 = $("#img4").attr("type");
        var img5 = $("#img5").attr("type");
        $.ajax({
            url: "http://localhost:8080/SnacksShop/boss.do?type=addBusinessLicense",
            type: "post",
            data:{
                img1:img1,
                img2:img2,
                img3:img3,
                img4:img4,
                img5:img5
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                console.log(obj);
                if (obj.status == '200'){
                    layer.alert('修改成功！',{
                        title: '提示框',
                        icon:1,
                    });
                }else {
                    layer.alert('修改失败！',{
                        title: '提示框',
                        icon:0,
                    });
                }
            },
            error:function (data){

            }
        });
        $(".license").attr("disabled", true);
        $('.businessLicense').find('.btn-success').css({'display': 'none'});
    }

    //文件上传
    $("#upload").change(function (){
        var upload_input = $("#upload").val();
        if(upload_input == ""){
            layer.alert("未选中文件！\r\n",{
                title: '提示框',
                icon:0,
            });
            return ;
        }
        var formData = new FormData();
        // console.log($("#upload")[0].files.length)
        for (var i = 0; i < $("#upload")[0].files.length; i++) {
            // console.log($("#upload")[0].files[i])
            formData.append("file",$("#upload")[0].files[i]);
        }
        fileUp(formData,$("#img"));
    });
    //初始化宽度、高度
    $(".admin_modify_style").height($(window).height());
    $(".recording_style").width($(window).width()-400);
    //当文档窗口发生改变时 触发
    $(window).resize(function(){
        $(".admin_modify_style").height($(window).height());
        $(".recording_style").width($(window).width()-400);
    });
    //修改密码
    function change_Password(){
        layer.open({
            type: 1,
            title:'修改密码',
            area: ['300px','300px'],
            shadeClose: true,
            content: $('#change_Pass'),
            btn:['确认修改'],
            yes:function(index, layero){
                if ($("#password").val()==""){
                    layer.alert('原密码不能为空!',{
                        title: '提示框',
                        icon:0,

                    });
                    return false;
                }
                if ($("#Nes_pas").val()==""){
                    layer.alert('新密码不能为空!',{
                        title: '提示框',
                        icon:0,

                    });
                    return false;
                }

                if ($("#c_mew_pas").val()==""){
                    layer.alert('确认新密码不能为空!',{
                        title: '提示框',
                        icon:0,

                    });
                    return false;
                }
                var reg1 = /([a-zA-Z0-9])/;  //密码验证
                if(!$("#c_mew_pas").val || $("#c_mew_pas").val() != $("#Nes_pas").val() )
                {
                    layer.alert('密码不一致!',{
                        title: '提示框',
                        icon:0,

                    });
                    return false;
                }else if (!reg1.test($("#Nes_pas").val())){
                    layer.alert('密码必须由数字和大小写字母!',{
                        title: '提示框',
                        icon:0,

                    });
                }
                else{
                    var oldPwd = $("#password").val();
                    var newPwd = $("#Nes_pas").val();
                    $.ajax({
                        url: "http://localhost:8080/SnacksShop/boss.do?type=updateBossPwd",
                        type: "post",
                        data:{
                            oldPwd:oldPwd,
                            newPwd:newPwd
                        },
                        crossDomain: true,
                        xhrFields: {
                            withCredentials: true
                        },
                        type: "post",
                        success:function (data){
                            var obj = JSON.parse(data);
                            if (obj.status == '200'){
                                layer.alert('修改成功！',{
                                    title: '提示框',
                                    icon:1,
                                });
                                layer.close(index);
                            }else {
                                layer.alert('原密码错误！',{
                                    title: '提示框',
                                    icon:0,
                                });
                            }
                        },
                        error:function (data){

                        }
                    });

                }
            }
        });
    }

    //验证信息
    function verifyInfo(type,info,errorText,element) {
        $.ajax({
            url: "http://localhost:8080/SnacksShop/boss.do?type=verifyBossInfo&verifyType="+type,
            type: "post",
            data:{
                verifyInfo:info
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                if (obj.status == '200'){
                    layer.alert(errorText+"已存在！\r\n",{
                        title: '提示框',
                        icon:0,
                    });
                    element.attr("value",true);
                }else {
                    element.attr("value",false);
                }
            },
            error:function (data){

            }
        });
    }

    //验证修改之后的用户名是否存在
    document.getElementById("username").addEventListener("blur",function (){
        var username = $("#username").val();
        var type = "name";
        var errorText = "用户";
        verifyInfo(type,username,errorText,$("#username"));
    });
    //验证手机号格式和是否存在
    document.getElementById("iphone").addEventListener("blur",function (){
        var iphone = $("#iphone").val();
        var pattern = /^1\d{10}$/;
        if (pattern.test(iphone)){
            verifyInfo("iphone",iphone,"手机号码",$("#iphone"));
        }else {
            layer.alert("手机号码有误 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
    });
    //验证邮箱格式和是否存在
    document.getElementById("email").addEventListener("blur",function (){
        var email = $("#email").val();
        var pattern = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/g;
        if (pattern.test(email)){
            verifyInfo("email",email,"邮箱",$("#email"));
        }else {
            layer.alert("邮箱有误 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
    });
    //验证身份证号码格式和是否存在
    document.getElementById("idCard").addEventListener("blur",function (){
        var idCard = $("#idCard").val();
        var pattern =  /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if (pattern.test(idCard)){
            verifyInfo("idCard",idCard,"身份证号码",$("#idCard"));
        }else {
            layer.alert("身份证号码有误 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
    });
    //验证店铺名是否存在
    document.getElementById("businessName").addEventListener("blur",function (){
        var businessName = $("#businessName").val();
        $.ajax({
            url: "http://localhost:8080/SnacksShop/boss.do?type=verifyBusinessName",
            type: "post",
            data:{
                businessName:businessName
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                if (obj.status == '200'){
                    layer.alert("店铺名已存在！\r\n",{
                        title: '提示框',
                        icon:0,
                    });
                    $("#businessName").attr("value",true);
                }else {
                    $("#businessName").attr("value",false);
                }
            },
            error:function (data){

            }
        });
    })
</script>
<script>
    jQuery(function($) {
        var oTable1 = $('#sample-table').dataTable( {
            "aaSorting": [[ 1, "desc" ]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[0,2,3,4,5,6]}// 制定列不参与排序
            ] } );


        $('table th input:checkbox').on('click' , function(){
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function(){
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
    });</script>
